package com.zhanglijie.improve.atomic.four;

import com.zhanglijie.theory.threadpermessage.MyServer;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/9/7 0007 23:39
 */
public class TestMyStack {
    public static void main(String[] args) throws InterruptedException {
        MyStack myStack = new MyStack();
        //入栈线程一
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 31; i++) {
                MyStack.Node node = new MyStack.Node(i);
                System.out.println(node.value+" =>要入栈了");
                myStack.push(node);
            }
        },"t1");

        //入栈线程二
        Thread t2 = new Thread(() -> {
            for (int i = 31; i < 61; i++) {
                MyStack.Node node = new MyStack.Node(i);
                System.out.println(node.value+" =>要入栈了");
                myStack.push(node);
            }
        },"t2");

        //出战线程
        Thread t3 = new Thread(() -> {
            for (int i = 0; i < 61; i++) {
                MyStack.Node pop = myStack.pop();
                if(pop != null){
                    System.out.println(pop.value+"=》 出栈了"
                        + "");
                }
            }
        },"t3");
        t1.start();
        t2.start();
        t3.start();
        t1.join();
        t2.join();
        t3.join();
        myStack.printStack();


    }
}
